// 引入二次封装的axios
import request from '@/request'


// 获取所有男性的接口
export const getManList = () => {
    // 返回一个promise对象
    return new Promise((resolve, reject) => {
        request.get('/api/users/male')
        .then(
            res => {
                resolve(res)
            }
        )
        .catch(
            err => {
                reject(err)
            }
        )
    })
}

// 获取所有女性的接口
export const getFemaleList = () => {
    // 返回一个promise对象
    return new Promise((resolve, reject) => {
        request.get('/api/users/female')
        .then(
            res => {
                resolve(res)
            }
        )
        .catch(
            err => {
                reject(err)
            }
        )
    })
}
// 随机抽取
export const getRandomPerson = (sex, address) => {
    // 返回一个promise对象
    return new Promise((resolve, reject) => {
        request.get('/api/users/random?sex=' + sex + '&address=' + address)
        .then(
            res => {
                resolve(res)
            }
        )
        .catch(
            err => {
                reject(err)
            }
        )
    })
}

// 添加一个用户
export const addUser = (contact, sex, address) => {
    // 返回一个promise对象
    return new Promise((resolve, reject) => {
        request.post('/api/users/add', {contact, sex, address})
        .then(
            res => {
                resolve(res)
            }
        )
        .catch(
            err => {
                reject(err)
            }
        )
    })
}

// 举报一个用户
export const reportUser = (id) => {
    // 返回一个promise对象
    return new Promise((resolve, reject) => {
        request.post('/api/users/report', {id})
        .then(
            res => {
                resolve(res)
            }
        )
        .catch(
            err => {
                reject(err)
            }
        )
    })
}